<template>
  <div class="goods-comment-image">
    <div class="list">
      <a
        href="javascript:;"
        v-for="(item,i) in pictures" :key="i"
        :class="{active:i === index}"
        @click="changeActive(i)"
      >
        <img :src="item" alt="">
      </a>
    </div>
    <div class="preview" v-if="index === 0 || index">
        <img :src="pictures[index]" alt="">
        <span @click="close">×</span>
    </div>
  </div>
</template>
<script>
import { ref } from 'vue'
export default {
  name: 'GoodsCommentImage',
  props: {
    pictures: {
      type: Array,
      default: () => []
    }
  },
  setup () {
    const index = ref(null)
    // 激活图片active
    const changeActive = (i) => {
      index.value = i
    }

    // 关闭图片弹层
    const close = () => {
      index.value = null
    }
    return { changeActive, index, close }
  }
}
</script>
<style scoped lang="less">
.goods-comment-image {
  .list {
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
    a {
      width: 120px;
      height: 120px;
      border:1px solid #e4e4e4;
      margin-right: 20px;
      margin-bottom: 10px;
      img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
      &.active {
        border-color: @xtxColor;
      }
    }

  }
  .preview {
        width: 480px;
        height: 480px;
        border: 1px solid #e4e4e4;
        position: relative;
        background-color: #f8f8f8;
        margin-bottom: 20px;
        img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
        span {
            position: absolute;
            top: 0;
            right: 0;
            width: 30px;
            height: 30px;
            background-color: rgba(0,0,0,.2);
            line-height: 30px;
            text-align: center;
            color: #fff;
            font-size: 20px;
            font-weight: normal;
            cursor: pointer;
        }
    }
}
</style>
